package com.burgeon.backend.config;


import com.burgeon.backend.interceptor.AppInterceptor;
import com.burgeon.backend.interceptor.BackendInterceptor;
import com.burgeon.backend.interceptor.ImageInterceptor;
import com.burgeon.backend.interceptor.UserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {



    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 创建拦截器对象
        HandlerInterceptor backInterceptor = new BackendInterceptor();
        HandlerInterceptor userInterceptor = new UserInterceptor();
        HandlerInterceptor appInterceptor = new AppInterceptor();
        HandlerInterceptor imageInterceptor = new ImageInterceptor();
        // 白名单
        List<String> list = new ArrayList<>();

        list.add("/web/css/**");
        list.add("/web/images/**");
        list.add("/web/js/**");
        list.add("/web/assets/css/**");
        list.add("/web/assets/chartist/**");
        list.add("/web/assets/fonts/**");
        list.add("/web/assets/images/**");
        list.add("/web/assets/js/**");

        list.add("/complement/**");
        list.add("/test/**");
        list.add("/vip/**");
        list.add("/tool/**");
        list.add("/backend/**");
        list.add("/store/**");
        list.add("/checkcode/**");
        list.add("/messageTemplate/item/");
        list.add("/messageTemplate/reviews/");
        list.add("/messageTemplate/repetition/");

        list.add("/coupon/showconversion/");
        list.add("/coupon/conversion/");

        list.add("/web/login-system.html");
        list.add("/web/attestation.html");
        list.add("router.map.qq.com/**");
        list.add("/user/**");
        list.add("/wechat/**");
        list.add("/shop/**");
        list.add("/wxapp/**");
        list.add("/shopbackent/**");
        //公众号证书
        list.add("/MP_verify_bcAOct3TCMxU1nZ7.txt");
        list.add("/MP_verify_p6GVzfY6hJtVNfqP.txt");
        list.add("/MP_verify_xXE5f1yZ5DnOrVUX.txt");
        list.add("/MP_verify_ox1H0RFO2CNddfnA.txt");
        list.add("/MP_verify_8rrIXYcnTjRHtlES.txt");

        list.add("/oTnflZt8VA.txt");
        //添加拦截器
        //registry.addInterceptor(backInterceptor).addPathPatterns("/**").excludePathPatterns(list);
        registry.addInterceptor(userInterceptor).addPathPatterns(
                "/user/user.html", "/user/user-coupon.html","/user/user-item.html",
                "/user/user-store.html","/user/complement.html","/user/vip-recharge-i.html",
                "vip-recharge-p.html");
        registry.addInterceptor(appInterceptor).addPathPatterns("/shop/sys/test");
//        file:D:/code/
        //registry.addInterceptor(imageInterceptor).addPathPatterns("/imgapp/**");


    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/img/**").addResourceLocations("file:/root/code/img/");
    }




}
